/*
 * Copyright [2013-2021], Alibaba Group Holding Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.alibaba.polardbx.druid.bvt.sql.eval;

import com.alibaba.polardbx.druid.sql.visitor.SQLEvalVisitorUtils;
import junit.framework.TestCase;
import org.junit.Assert;

public class LikeTest extends TestCase {

    public void test_any_0() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%"));
    }

    public void test_any_1() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%%"));
    }

    public void test_any_2() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%b%"));
    }
    
    public void test_any_3() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "a%"));
    }

    public void test_any_4() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcdefg", "%g"));
    }

    public void test_single_0() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("a", "_"));
    }

    public void test_single_1() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("ab", "__"));
    }
    
    public void test_single_2() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcd", "a__d"));
    }
    
    public void test_single_3() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcdf", "a__d_"));
    }
    
    public void test_range_0() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("abcdf", "abcd[a-f]"));
    }
    
    public void test_range_1() throws Exception {
        Assert.assertFalse(SQLEvalVisitorUtils.like("abcdf", "abcd[a-e]"));
    }
    
    public void test_range_2() throws Exception {
        Assert.assertTrue(SQLEvalVisitorUtils.like("ab", "a[abf]"));
    }
}
